/**
 * 0103
 *  
 * @Author : roryrywang
 * @DateTime : 24-8-28 上午11:05
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;

    TreeNode() : val(0), left(nullptr), right(nullptr) {}

    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}

    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class Solution {
public:
    vector<vector<int>> res;

    void dfs(TreeNode *root, int k) {
        if (root == nullptr) return;
        if (k >= res.size()) {
            res.push_back({});
        }
        if (k % 2 == 1) {
            res[k].insert(res[k].begin(), root->val);
        } else {
            res[k].push_back(root->val);
        }
        dfs(root->left, k + 1);
        dfs(root->right, k + 1);
    }

    vector<vector<int>> zigzagLevelOrder(TreeNode *root) {
        dfs(root, 0);
        return res;
    }
};

int main() {

    return 0;
}